//
//  ShoppingCartCell.m
//  Yanwei
//
//  Created by 刘文 on 17/4/12.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#import "ShoppingCartCell.h"
#import "NSDate+Utils.h"

#import "NumberKeyboardAndToolTextField.h"
#import <UIImageView+WebCache.h>
#import "ShoppingCartStoreTagView.h"
/**
#import "ConfirmIdentityView.h"
#import "UserIdentityInstructionView.h"
#import "IdentityInfoListModel.h"
 */
#import "AffirmOrdeGoodsNumberView.h"

@interface ShoppingCartCell () <UITextFieldDelegate>

@property (assign, nonatomic) ClickedViewTypeInShoppingCart clickedViewTypeInShoppingCart;
@property (strong, nonatomic) UILabel * selectLabel;//勾选标记
@property (strong, nonatomic) UIImageView * goodsImageView;//商品缩略图
#pragma mark - 非编辑状态
@property (strong, nonatomic) UIView * goodsDataBkgView;//非编辑状态的背景
@property (strong, nonatomic) UILabel * goodsTitleLabel;//标题
@property (strong, nonatomic) UILabel * subheadLabel;//副标题(规格：xxxx)
@property (strong, nonatomic) UILabel * sellPriceLabel;//售价
@property (strong, nonatomic) UILabel * originalPriceLabel;//原价
@property (strong, nonatomic) UILabel * countLabel;//商品数量
@property (strong, nonatomic) UILabel * VIPLabel;//专享
@property (nonatomic, strong) UILabel *markLabel; // 商品标题标签
#pragma mark - 编辑状态
@property (strong, nonatomic) UIView * goodsEditBkgView;//编辑状态的背景
@property (strong, nonatomic) UILabel * downArrowLabel;//下箭头
@property (strong, nonatomic) UILabel * specificationOfGoodsLabel;//商品规格
@property (strong, nonatomic) UILabel * goodsPriceLabel;//商品价格
@property (strong, nonatomic) UILabel * subtractLabel;//减
@property (strong, nonatomic) NumberKeyboardAndToolTextField * countTextField;//数量
@property (strong, nonatomic) UILabel * addLabel;//加
@property (strong, nonatomic) UIView * defectMarkView;//缺货标记
@property (nonatomic, assign) NSInteger kMaxNum;
@property (nonatomic, strong) UIView *lineView;
@property (strong, nonatomic) UILabel *topSubtractLabel;//减
@property (strong, nonatomic) NumberKeyboardAndToolTextField * topCountTextField;//数量
@property (strong, nonatomic) UILabel *topAddLabel;//加
#pragma mark - 征订
@property (nonatomic, strong) UILabel * lotteryLabel;
@property (nonatomic, copy) ShoppingCartStoreTagView *shoppingCartStoreTagView;
@property (nonatomic, copy) UILabel *dpLabel;
@property (nonatomic, copy) GoodsModel *model;
#pragma mark 跨境
@property (nonatomic, strong) UILabel *marketNameLabel;
/**
@property (nonatomic, strong) ConfirmIdentityView *identityView; // 实名
 */
/** 分割线 */
@property (nonatomic, strong) UIView *cellSepView;
/** 数量编辑内容视图 */
@property (nonatomic, strong) UIView *goodsNumerContentView;
#pragma mark - 限时购新增
/** 限时购信息label,只在购物车中时会显示 */
@property (nonatomic, strong) UILabel *limitBuyInfoLabel;
/** 限购数量，只在购物车中显示 */
@property (nonatomic, strong) UILabel *carLimitMaxLabel;
/** 限购数量，只在购买数量设置中显示 */
@property (nonatomic, strong) UILabel *editLimitMaxLabel;

@end

@implementation ShoppingCartCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier clickedViewTypeInShoppingCart:(ClickedViewTypeInShoppingCart)type {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clickedViewTypeInShoppingCart = type;
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    }
    return self;
}

- (void)setEditStatus:(BOOL)editStatus {
    _editStatus = editStatus;
    self.goodsDataBkgView.hidden = editStatus;
    self.goodsEditBkgView.hidden = !editStatus;
}
- (void)setShowShoppingCartStoreTagView:(BOOL)showShoppingCartStoreTagView {
    _showShoppingCartStoreTagView = showShoppingCartStoreTagView;
    
    self.shoppingCartStoreTagView.hidden =! _showShoppingCartStoreTagView;
}

- (void)setModel:(GoodsModel *)model isOrderDetail:(BOOL)isOrderDetail {
    _model = model;

    [self updateSelectState];
    
    /*
    if (_model.goodsClassify != GoodsClassifyTypeSubscribe) {
        self.shoppingCartStoreTagView.hidden =! self.showShoppingCartStoreTagView;
    } else {
        self.shoppingCartStoreTagView.hidden = YES;
    }
    
    if (self.shoppingCartStoreTagView.hidden) {
        [self.goodsImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).with.offset(5);
        }];
    } else {
        if (_model.promotion.campaignList.count == 0) {
            [self hideShoppingCartStoreTagViewMethod];
        } else {
            [self showShoppingCartStoreTagViewMethod];
            [_model.promotion.campaignList enumerateObjectsUsingBlock:^(PromoteSpuRspCouponsAndCampaignsModel  *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                self.shoppingCartStoreTagView.model = obj;
            }];
        }
    }
    
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:PacketImageUrl(model.imagePath)] placeholderImage:NewStoreDefault];
    if (model.benefit == JoinHuiyuanMallType) {
        // 商品标题
        [self updateTitleContent:@" 积分商城 "];
        
        self.sellPriceLabel.text = [NSString stringWithFormat:@"%@ 积分", @(model.benefitNumber)];//@"580 积分";
        if (_model.regularPrice.hasValue && ([_model.regularPrice floatValue] > [_model.sellingPrice floatValue])) {
            self.originalPriceLabel.hidden = NO;
            self.originalPriceLabel.text = [NSString stringWithFormat:@"市场参考价：%@元", model.regularPrice];
        } else {
            self.originalPriceLabel.hidden = YES;
        }
    } else {
        if (model.goodsClassify == GoodsClassifyTypeSubscribe) {
            // 商品标题
            [self updateTitleContent:@" 征订 "];
        } else {
            // 商品标题
            self.lotteryLabel.hidden = YES;
            self.goodsTitleLabel.text = model.title;
            self.originalPriceLabel.hidden = NO;
        }
        
        if (model.unitPrice.hasValue) {
            self.sellPriceLabel.text = [NSString stringWithFormat:@"¥%@", model.unitPrice];//@"¥310.00";
        } else {
            self.sellPriceLabel.text = [NSString stringWithFormat:@"¥%@", model.sellingPrice];//@"¥310.00";
            if (model.limitBuyState == NewStoreLimitBuyState_Process && model.limitInventoryCount) {
                //进行中且有库存才显示限时价
                self.sellPriceLabel.text = [NSString stringWithFormat:@"¥%@", model.limitSellingPrice];//@"¥310.00";
            }
        }
        
        if (_model.regularPrice.hasValue && ([_model.regularPrice floatValue] > [_model.sellingPrice floatValue])) {
            self.originalPriceLabel.hidden = NO;
            self.originalPriceLabel.text = [NSString stringWithFormat:@"¥ %@", model.regularPrice];
        } else {
            self.originalPriceLabel.hidden = YES;
        }
        
        if (self.originalPriceLabel.text.hasValue) {
            // 中划线
            NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
            NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:self.originalPriceLabel.text attributes:attribtDic];
            
            //赋值
            self.originalPriceLabel.attributedText = attribtStr;
        } else {
            self.originalPriceLabel.text = @"";
        }
    }

    
    //规格赋值
    self.subheadLabel.text = [NSString stringWithFormat:@"%@", model.name];
    
    self.specificationOfGoodsLabel.text = [NSString stringWithFormat:@"已选择：%@", model.name];
    self.goodsPriceLabel.text = [NSString stringWithFormat:@"¥%@", model.sellingPrice];
    self.countTextField.text = [NSString stringWithFormat:@"%@", @(model.number)];
    [self updateUIData];
    
    self.model.tempNumber = self.countTextField.text.integerValue;
    
    if (self.clickedViewTypeInShoppingCart == ClickedViewTypeInShoppingCartNoraml || self.clickedViewTypeInShoppingCart == ClickedViewTypeInShoppingCartChangeStandard) {
        if (model.goodsState == GoodsStateTypeActive || model.goodsState == GoodsStateTypeSelling || model.goodsState == GoodsStateTypeOnline) {
            self.selectLabel.userInteractionEnabled = YES;
            self.defectMarkView.hidden = YES;
        } else {
            self.selectLabel.userInteractionEnabled = NO;
            self.defectMarkView.hidden = NO;
        }
    }
    
    self.kMaxNum = _model.inventory;
    if (model.limitBuyState == NewStoreLimitBuyState_Process) {
        self.kMaxNum = model.inventory > model.limitMax ? model.limitMax : model.inventory;
    }
    
    self.marketNameLabel.hidden = YES;
    CGFloat vipWidth = 0;
    if (_model.showEmployeePrice && _model.goodsClassify != GoodsClassifyTypeSubscribe && _model.benefit != JoinHuiyuanMallType) {
        //显示员工专享的label  需要判断是否是员工并且有员工价
        vipWidth = 25;
    }
    
    if (self.fromShoppingCart) {
        //购物车里
        self.topCountTextField.text = [NSString stringWithFormat:@"%@", @(model.number)];
        [self topUpdateUIData];
        
        [self.goodsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsDataBkgView).with.offset(8);
            make.top.equalTo(self.goodsDataBkgView).with.offset(10);
            make.height.mas_lessThanOrEqualTo(@42);
            make.right.equalTo(self.goodsDataBkgView).with.offset(-40);
        }];
        [self.originalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsDataBkgView).with.offset(8);
            make.bottom.equalTo(self.goodsDataBkgView).offset(-10);
        }];
        [self.sellPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsTitleLabel);
            make.bottom.equalTo(self.originalPriceLabel.mas_top).with.offset(- 2);
        }];
        [self.VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.sellPriceLabel.mas_right).with.offset(4);
            make.centerY.equalTo(self.sellPriceLabel);
            make.height.mas_equalTo(14);
            make.width.mas_equalTo(vipWidth);
        }];
        
        self.limitBuyInfoLabel.hidden = !(model.inLimitBuy && model.limitInventoryCount);
        if (!self.limitBuyInfoLabel.hidden) {
            if (model.limitBuyState < NewStoreLimitBuyState_Process) {
                NSString *startTimeStr = [model.limitStartDate stringWithFormat:@"MM月dd日HH:mm"];
                self.limitBuyInfoLabel.text = [NSString stringWithFormat:@"限时购 %@后可¥%@购买",startTimeStr,model.limitSellingPrice];
                self.VIPLabel.hidden = NO;
                self.carLimitMaxLabel.hidden = YES;
            } else if (model.limitBuyState == NewStoreLimitBuyState_Process){
                NSDateComponents *intervalComponents = [NSDate daysComponentsOffsetBetweenStartDate:model.limitServerDate endDate:model.limitEndDate];
                NSString *daysStr = intervalComponents.day ? [NSString stringWithFormat:@"%@天",@(intervalComponents.day)] : @"";
                self.limitBuyInfoLabel.text = [NSString stringWithFormat:@"限时购 还剩%@%@时%@分结束",daysStr,@(intervalComponents.hour),@(intervalComponents.minute)];
            
                self.VIPLabel.hidden = YES;
                self.carLimitMaxLabel.hidden = NO;
                self.carLimitMaxLabel.text = [NSString stringWithFormat:@"限购%@件",@(model.limitMax)];
            }
        }
    } else {
        //其它地方  比如订单....
        self.sellPriceLabel.text = [NSString stringWithFormat:@"¥%@",model.unitPrice];

        NSString * str = [NSString stringWithFormat:@"X%@", @(model.number)];
        NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:str];
        NSRange strRange = {0, 1};
        [attributedString addAttribute:NSFontAttributeName value:APPFONT(9) range:strRange];
        strRange = NSMakeRange(1, attributedString.length - 1);
        [attributedString addAttribute:NSFontAttributeName value:APPFONT(11) range:strRange];
        self.countLabel.attributedText = attributedString;
        
        if (model.groupBuying) {
            // 商品标题
             [self updateTitleContent:@" [拼团] "];
            // 隐藏专享
            self.VIPLabel.hidden = YES;
        } else {
            // 显示专享
            self.VIPLabel.hidden = NO;
        }
        
        //不是限时购的情况
        [self.VIPLabel roundBorderWithBorderDirection:BorderDirectionALL lineWidth:1 color:Color175030];
        self.VIPLabel.text = @"专享";
        self.VIPLabel.textColor = Color175030;
        self.editLimitMaxLabel.hidden = YES;
        //如果是限时购,且有库存量
        if (model.inLimitBuy) {
            //限时购标签
            self.VIPLabel.hidden = NO;
            self.VIPLabel.text = @"限时购";
            vipWidth = 36;
            [self.VIPLabel roundBorderWithBorderDirection:BorderDirectionALL lineWidth:1 color:Color20812847];
            self.VIPLabel.textColor = Color20812847;
            //限购数量
            self.editLimitMaxLabel.hidden = NO;
            self.editLimitMaxLabel.text = [NSString stringWithFormat:@"限购%@件",@(model.limitMax)];
        }

        if (isOrderDetail) {
            self.sellPriceLabel.font = APPBOLDPINGFANGFONT(14);
            self.originalPriceLabel.font = APPFONT(14);
            // 价格布局
            [self.sellPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.goodsDataBkgView).offset(-15);
                make.top.equalTo(self.goodsImageView);
            }];
            [_VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.goodsDataBkgView).offset(-15);
                make.centerY.equalTo(self.countLabel);
                make.height.mas_equalTo(14);
                make.width.mas_equalTo(vipWidth);
            }];
            [self.originalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.sellPriceLabel);
                make.top.equalTo(self.sellPriceLabel.mas_bottom).offset(2);
            }];
            [self.goodsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.goodsDataBkgView).with.offset(8);
                make.right.equalTo(self.goodsDataBkgView).offset(-78);
                make.top.equalTo(self.goodsImageView);
            }];
            // 规格数
            [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.goodsTitleLabel);
                make.bottom.equalTo(self.goodsDataBkgView).with.offset(- 10);
            }];
        } else {
            [self.goodsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.goodsDataBkgView).with.offset(8);
                make.top.equalTo(self.goodsImageView);
                make.right.equalTo(self.goodsDataBkgView).with.offset(-40);
            }];
            // 价格布局
            [self.sellPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.goodsImageView);
                make.left.equalTo(self.goodsTitleLabel);
            }];
            [_VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.sellPriceLabel.mas_right).with.offset(4);
                make.centerY.equalTo(self.sellPriceLabel);
                make.height.mas_equalTo(14);
                make.width.mas_equalTo(vipWidth);
            }];
            if (self.originalPriceLabel.text.hasValue) {
                self.marketNameLabel.hidden = NO;
                [self.marketNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    if (self.VIPLabel.hidden == NO) {
                        make.left.equalTo(self.VIPLabel.mas_right).with.offset(5);
                    } else {
                        make.left.equalTo(self.sellPriceLabel.mas_right).with.offset(5);
                    }
                    make.centerY.equalTo(self.sellPriceLabel);
                }];
                [self.originalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.marketNameLabel.mas_right);
                    make.centerY.equalTo(self.sellPriceLabel);
                }];
            }
            // 规格数
            [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.goodsDataBkgView).with.offset(-15);
                make.centerY.equalTo(self.sellPriceLabel);
            }];
        }
        
        self.goodsImageView.layer.borderWidth = 0.5;
        self.goodsImageView.layer.borderColor = Color217.CGColor;
        self.goodsImageView.layer.masksToBounds = YES;
        self.goodsImageView.layer.cornerRadius = 2;
    }
    
    if (model.overseas && model.title.hasValue) {
        self.markLabel.hidden = self.editStatus;
        NSMutableParagraphStyle *muParagraph = [[NSMutableParagraphStyle alloc]init];
        muParagraph.lineSpacing = 2;
        muParagraph.firstLineHeadIndent = 35;
        
        NSString *title = model.title;
        if (model.groupBuying) {
            self.lotteryLabel.hidden = YES;
            title = [NSString stringWithFormat:@" [拼团] %@",title];
        }
        
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSParagraphStyleAttributeName : muParagraph}];
        if ([title hasPrefix:@" [拼团] "]) {
            [attr addAttributes:@{NSForegroundColorAttributeName : Color175030} range:NSMakeRange(0, @" [拼团] ".length)];
        }
        self.goodsTitleLabel.attributedText = attr;
    } else {
        self.markLabel.hidden = YES;
    }
    
    if (self.needEditGoodsNumber) { // 确认订单页增加编辑数量    
        self.goodsNumerView.model = model;
        self.goodsNumerContentView.hidden = NO;
    } else {
        self.goodsNumerContentView.hidden = YES;
    }
    
    if (model.noSupportMsg.hasValue) {
        self.identityView.hidden = NO;
        [self.identityView setTitle:@"本商品暂时不支持当前地址购买" hasArrow:NO enabled:NO showTopLine:NO];
        if (self.needEditGoodsNumber) {
            [self.identityView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.contentView).offset(-40);
            }];
        } else {
            [self.identityView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.contentView);
            }];
        }
    } else {
        self.identityView.hidden = YES;
    }
     */
}

- (void)setOrderListPurchaseType:(OrderListPurchaseType)orderListPurchaseType {
    _orderListPurchaseType = orderListPurchaseType;
    
    switch (_orderListPurchaseType) {
        case OrderListTypeDIRECT:
            self.dpLabel.backgroundColor = Color175030;
            [self updateDPTitleContent:@"直购"];
            break;
        case OrderListTypeTrackerBid: {
            self.dpLabel.backgroundColor = RGBACOLOR(255, 113, 66, 1);
            /**
            NSString *trackerOrgNameString = self.model.trackerOrgName.hasValue ? self.model.trackerOrgName : @"跟标";
            [self updateDPTitleContent:trackerOrgNameString];
             */
            break;
        }
        default:
            break;
    }
}

- (void)setFromShoppingCart:(BOOL)fromShoppingCart {
    _fromShoppingCart = fromShoppingCart;
}
- (void)setShowLine:(BOOL)showLine {
    _showLine = showLine;
    
    self.lineView.hidden =! _showLine;
}
- (void)setShowSepLine:(BOOL)showSepLine {
    _showSepLine = showSepLine;
    self.cellSepView.hidden = !showSepLine;
}
- (void)setShoppingCartListType:(NSInteger)shoppingCartListType {
    _shoppingCartListType = shoppingCartListType;
}
- (void)hideShoppingCartStoreTagViewMethod {
    self.showShoppingCartStoreTagView = NO;
    [self.goodsImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).with.offset(5);
    }];
}
- (void)showShoppingCartStoreTagViewMethod {
    self.showShoppingCartStoreTagView = YES;
    [self.goodsImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).with.offset(30);
    }];
}

/** 更新商品标题的内容 */
- (void)updateTitleContent:(NSString *)lotteryString {
    CGSize size = TextSize(lotteryString, APPFONT(11));
    self.lotteryLabel.hidden = NO;
    self.lotteryLabel.text = lotteryString;
    if ([lotteryString containsString:@"拼团"]) {
        _lotteryLabel.layer.masksToBounds = NO;
        _lotteryLabel.layer.cornerRadius = 0;
        _lotteryLabel.layer.borderColor = [[UIColor clearColor] CGColor];
        _lotteryLabel.layer.borderWidth = 0;
    } else {
        _lotteryLabel.layer.masksToBounds = YES;
        _lotteryLabel.layer.cornerRadius = 2;
        _lotteryLabel.layer.borderColor = [Color175030 CGColor];
        _lotteryLabel.layer.borderWidth = 1;
    }
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.model.title];
    NSMutableParagraphStyle * style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.firstLineHeadIndent = size.width + 7;//首行头缩进
    [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [self.model.title length])];
    self.goodsTitleLabel.attributedText = attrString;
}
/** 更新商品标题的内容 */
- (void)updateDPTitleContent:(NSString *)lotteryString {
    CGSize size = TextSize(lotteryString, APPFONT(11));
    self.dpLabel.hidden = NO;
    self.dpLabel.text = lotteryString;
    [self.dpLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsTitleLabel);
        make.top.equalTo(self.goodsTitleLabel).with.offset(2);
        make.width.mas_equalTo(size.width +10);
        make.height.mas_equalTo(14);
    }];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.model.title];
    NSMutableParagraphStyle * style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.firstLineHeadIndent = size.width + 16;//首行头缩进
    [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [self.model.title length])];
    self.goodsTitleLabel.attributedText = attrString;
}
- (void)clickedEvent:(ClickedViewTypeInShoppingCart)type data:(id)data {
    if (self.clickedTypeInViewBlock) {
        self.clickedTypeInViewBlock(type, data);
    }
}
- (void)updateUIData {
    if (self.countTextField.text.integerValue > self.model.minimum) {
        [self.subtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0x959595)];
        self.subtractLabel.textColor = HEXCOLOR(0x000000);
    } else {
        [self.subtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
        self.subtractLabel.textColor = HEXCOLOR(0xdbdbdb);
    }
    
    if (self.countTextField.text.integerValue < self.kMaxNum) {
        [self.addLabel roundBorderWithBorderDirection:BorderDirectionRight | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0x959595)];
        self.addLabel.textColor = HEXCOLOR(0x000000);
    } else {
        [self.addLabel roundBorderWithBorderDirection:BorderDirectionRight | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
        self.addLabel.textColor = HEXCOLOR(0xdbdbdb);
    }
}
- (void)topUpdateUIData {
    if (self.topCountTextField.text.integerValue > self.model.minimum) {
        self.topSubtractLabel.textColor = HEXCOLOR(0x000000);
        [self.topSubtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0x959595)];
    } else {
        self.topSubtractLabel.textColor = HEXCOLOR(0xdbdbdb);
        [self.topSubtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
    }
    
    if (self.topCountTextField.text.integerValue < self.kMaxNum) {
        self.topAddLabel.textColor = HEXCOLOR(0x000000);
        [self.topAddLabel roundBorderWithBorderDirection:BorderDirectionRight | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0x959595)];
    } else {
        self.topAddLabel.textColor = HEXCOLOR(0xdbdbdb);
        [self.topAddLabel roundBorderWithBorderDirection:BorderDirectionRight | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
    }
}
- (void)updateSelectState {
    if (self.clickedViewTypeInShoppingCart != ClickedViewTypeInShoppingCartOrderCell) {
        //需要展示勾选按钮的处理
        /**
        if (self.model.checked) {
            self.selectLabel.text = SELECT_D;
            self.selectLabel.textColor = Color175030;
        } else {
            self.selectLabel.text = SELECT_N;
            self.selectLabel.textColor = HEXCOLOR(0xcacaca);
        }
         */
    }
}


#pragma mark - <UITextFieldDelegate>
- (void)textFieldDidEndEditing:(UITextField *)textField {
    NSInteger maxNum = self.kMaxNum;
    /**
    maxNum = self.model.inventory;
    if (self.model.limitBuyState == NewStoreLimitBuyState_Process) {
        //不敢动前面的- -，再写一遍算了...
        maxNum = self.kMaxNum;
    }
    
    if ([textField.text integerValue] >= maxNum) {
        textField.text = [NSString stringWithFormat:@"%@", @(maxNum)];
    } else if ([textField.text integerValue] <= self.model.minimum) {
        textField.text = [NSString stringWithFormat:@"%@", @(self.model.minimum)];
    }
    self.model.tempNumber = textField.text.integerValue;
    if (textField.tag == 2) {
        [self topUpdateUIData];
    } else {
        self.model.changeEdit = YES;
        [self updateUIData];
    }
    */
    
    if (self.cliekedNumChangeBlock) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(-1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.cliekedNumChangeBlock();
        });
    }
}
- (void)changeTextField:(UITextField *)textField {
    NSInteger maxNum = self.kMaxNum;
    
    /**
    maxNum = self.model.inventory;
    if (self.model.limitBuyState == NewStoreLimitBuyState_Process) {
        //不敢动前面的- -，再写一遍算了...
        maxNum = self.kMaxNum;
    }
    if ([textField.text integerValue] >= maxNum) {
        textField.text = [NSString stringWithFormat:@"%@", @(maxNum)];
        
        NSString *kMaxNumString = [NSString stringWithFormat:@"最多只能购买%@件", @(self.kMaxNum)];
        jxt_showToastTitle(kMaxNumString, 1);
    }
    
    self.model.tempNumber = textField.text.integerValue;
    self.model.changeEdit = YES;
     */
    
    [self updateUIData];
}
- (void)topChangeTextField:(UITextField *)textField {
    NSInteger maxNum = self.kMaxNum;
    
    /**
    maxNum = self.model.inventory;
    
    if ([textField.text integerValue] >= maxNum) {
        textField.text = [NSString stringWithFormat:@"%@", @(maxNum)];
        
        NSString *kMaxNumString = [NSString stringWithFormat:@"最多只能购买%@件", @(self.kMaxNum)];
        jxt_showToastTitle(kMaxNumString, 1);
    }
    
    self.model.tempNumber = textField.text.integerValue;
     */
    [self topUpdateUIData];
}


#pragma mark - 懒加载
#pragma mark - 未编辑状态
- (UILabel *)selectLabel {
    if (!_selectLabel) {
        _selectLabel = [UILabel new];
        _selectLabel.font = ICONFONT(18);
        _selectLabel.textColor = HEXCOLOR(0xcacaca);
        [self.contentView addSubview:_selectLabel];
        [_selectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(@16);
            make.top.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView);
            make.width.mas_equalTo(@24);
        }];
        
        [_selectLabel tapUpWithBlock:^(UIView * v) {
            /**
            self.model.tempNumber = self.countTextField.text.integerValue;
            
            self.model.checked = !self.model.checked;
            [self clickedEvent:ClickedViewTypeInShoppingCartCheckGoods data:nil];
            [StoreRequestManager storeCheckedShoppingCartGoodsWithSid:@[self.model.sid] state:self.model.checked shoppingType:self.shoppingCartListType sucess:^(id data) {
                [self clickedEvent:ClickedViewTypeInShoppingCartCheckGoods data:data];
            } fail:^(NSString * error) {
                self.model.checked = !self.model.checked;
                [self clickedEvent:ClickedViewTypeInShoppingCartCheckGoods data:nil];
            }];
             */
        }];
    }
    return _selectLabel;
}
- (UIImageView *)goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [UIImageView new];
        _goodsImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_goodsImageView];
        if (self.clickedViewTypeInShoppingCart == ClickedViewTypeInShoppingCartOrderCell) {
            [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView).with.offset(15);
                make.top.equalTo(self.shoppingCartStoreTagView.mas_bottom).with.offset(5);
                make.height.mas_equalTo(100);
                make.width.equalTo(self.goodsImageView.mas_height);
            }];
        } else {
            [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.selectLabel.mas_right).with.offset(8);
                make.top.equalTo(self.shoppingCartStoreTagView.mas_bottom).with.offset(5);
                make.height.mas_equalTo(100);
                make.width.equalTo(self.goodsImageView.mas_height);
            }];
        }
    }
    return _goodsImageView;
}
- (UILabel *)goodsTitleLabel {
    if (!_goodsTitleLabel) {
        _goodsTitleLabel = [UILabel new];
        _goodsTitleLabel.font = APPFONT(14);
        _goodsTitleLabel.textColor = HEXCOLOR(0x353535);
        _goodsTitleLabel.numberOfLines = 2;
        [self.goodsDataBkgView addSubview:_goodsTitleLabel];
    }
    return _goodsTitleLabel;
}
- (UILabel *)subheadLabel {
    if (!_subheadLabel) {
        _subheadLabel = [UILabel new];
        _subheadLabel.font = APPFONT(11);
        _subheadLabel.numberOfLines = 1;
        _subheadLabel.textColor = HEXCOLOR(0x8a8a8a);
        [self.goodsDataBkgView addSubview:_subheadLabel];
        [_subheadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsTitleLabel);
            make.top.equalTo(self.goodsTitleLabel.mas_bottom).with.offset(4);
            make.right.equalTo(self.goodsTitleLabel);
        }];
    }
    return _subheadLabel;
}
- (UILabel *)sellPriceLabel {
    if (!_sellPriceLabel) {
        _sellPriceLabel = [UILabel new];
        _sellPriceLabel.font = APPFONT(14);
        _sellPriceLabel.textColor = Color175030;
        _sellPriceLabel.textAlignment = NSTextAlignmentLeft;
        [self.goodsDataBkgView addSubview:_sellPriceLabel];
    }
    return _sellPriceLabel;
}
- (UILabel *)originalPriceLabel {
    if (!_originalPriceLabel) {
        _originalPriceLabel = [UILabel new];
        _originalPriceLabel.font = APPFONT(10);
        _originalPriceLabel.textColor = HEXCOLOR(0x9f9f9f);
        _originalPriceLabel.textAlignment = NSTextAlignmentLeft;
        [self.goodsDataBkgView addSubview:_originalPriceLabel];
    }
    return _originalPriceLabel;
}
- (UILabel *)marketNameLabel {
    if (!_marketNameLabel) {
        _marketNameLabel = [[UILabel alloc] init];
        _marketNameLabel.text = @"市场均价";
        _marketNameLabel.textColor = HEXCOLOR(0x9f9f9f);
        _marketNameLabel.font = APPFONT(12);
        [self.goodsDataBkgView addSubview:_marketNameLabel];
    }
    return _marketNameLabel;
}
- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [UILabel new];
        _countLabel.font = APPFONT(11);
        [self.goodsDataBkgView addSubview:_countLabel];
    }
    return _countLabel;
}
- (UIView *)goodsDataBkgView {
    if (!_goodsDataBkgView) {
        _goodsDataBkgView = [UIView new];
        _goodsDataBkgView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_goodsDataBkgView];
        [_goodsDataBkgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsImageView.mas_right);
            make.top.equalTo(self.goodsImageView);
            make.bottom.equalTo(self.contentView);
            make.right.equalTo(self.contentView);
        }];
    }
    return _goodsDataBkgView;
}
- (UILabel *)VIPLabel {
    if (!_VIPLabel) {
        _VIPLabel = [UILabel new];
        _VIPLabel.cornerRadius = 3;
        [_VIPLabel roundBorderWithBorderDirection:BorderDirectionALL lineWidth:1 color:Color175030];
        _VIPLabel.text = @"专享";
        _VIPLabel.font = APPFONT(9);
        _VIPLabel.textColor = Color175030;
        _VIPLabel.textAlignment = NSTextAlignmentCenter;
        [self.goodsDataBkgView addSubview:_VIPLabel];
    }
    return _VIPLabel;
}


#pragma mark - 编辑状态
- (UIView *)goodsEditBkgView {
    if (!_goodsEditBkgView) {
        _goodsEditBkgView = [UIView new];
        _goodsEditBkgView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_goodsEditBkgView];
        [_goodsEditBkgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsImageView.mas_right);
            make.top.equalTo(self.goodsImageView);
            make.bottom.equalTo(self.contentView);
            make.right.equalTo(self.contentView);
        }];
    }
    return _goodsEditBkgView;
}
- (UILabel *)downArrowLabel {
    if (!_downArrowLabel) {
        _downArrowLabel = [UILabel new];
        _downArrowLabel.font = ICONFONT(15);
        _downArrowLabel.text = [NSString stringWithFormat:@"%@", N_DOWNARROW];
        _downArrowLabel.textColor = HEXCOLOR(0x818181);
        [self.goodsEditBkgView addSubview:_downArrowLabel];
        [_downArrowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.goodsEditBkgView);
            make.top.equalTo(self.goodsImageView);
            make.width.mas_equalTo(@41);
        }];
        
        [_downArrowLabel tapUpWithBlock:^(UIView *v) {
            [self clickedEvent:ClickedViewTypeInShoppingCartChangeStandard data:nil];
        }];
    }
    return _downArrowLabel;
}
- (UILabel *)specificationOfGoodsLabel {
    if (!_specificationOfGoodsLabel) {
        _specificationOfGoodsLabel = [UILabel new];
        _specificationOfGoodsLabel.font = APPFONT(15);
        _specificationOfGoodsLabel.numberOfLines = 1;
        _specificationOfGoodsLabel.textAlignment = NSTextAlignmentRight;
        [self.goodsEditBkgView addSubview:_specificationOfGoodsLabel];
        [_specificationOfGoodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.downArrowLabel.mas_left).with.offset(-1);
            make.left.equalTo(self.goodsEditBkgView).with.offset(8);
            make.top.equalTo(self.goodsImageView);
        }];
        
        [_specificationOfGoodsLabel tapUpWithBlock:^(UIView *v) {
            [self clickedEvent:ClickedViewTypeInShoppingCartChangeStandard data:nil];
        }];
    }
    return _specificationOfGoodsLabel;
}
- (UILabel *)addLabel {
    if (!_addLabel) {
        _addLabel = [UILabel new];
        _addLabel.font = APPFONT(16);
        _addLabel.text = @"+";
        _addLabel.cornerRadius = 1;
        _addLabel.textColor = HEXCOLOR(0x000000);
        _addLabel.textAlignment = NSTextAlignmentCenter;
        [self.goodsEditBkgView addSubview:_addLabel];
        [_addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.goodsEditBkgView).with.offset(-15);
            make.bottom.equalTo(self.goodsEditBkgView).with.offset(-10);
            if (ScreenWidth >320) {
                make.height.mas_equalTo(@25);
                make.width.mas_equalTo(@30);
            } else {
                make.height.mas_equalTo(25 *WIDTH);
                make.width.mas_equalTo(30 *WIDTH);
            }
        }];
        
        [_addLabel tapUpWithBlock:^(UIView * v) {
            NSInteger num = self.countTextField.text.integerValue + 1;
            /**
            if (num > self.model.inventory) {
                num -= 1;
            }
            self.model.tempNumber = num;
            self.countTextField.text = [NSString stringWithFormat:@"%@", @(num)];
            self.model.changeEdit = YES;
             */
            [self updateUIData];
        }];
    }
    return _addLabel;
}
- (NumberKeyboardAndToolTextField *)countTextField {
    if (!_countTextField) {
        _countTextField = [[NumberKeyboardAndToolTextField alloc] init];
        _countTextField.font = APPFONT(14);
        _countTextField.text = @"1";
        _countTextField.textAlignment = NSTextAlignmentCenter;
        _countTextField.keyboardType = UIKeyboardTypeNumberPad;
        _countTextField.delegate = self;
        [_countTextField addTarget:self action:@selector(changeTextField:) forControlEvents:UIControlEventEditingChanged];
        [_countTextField limitTextLength:4];
        [_countTextField roundBorderWithBorderDirection:BorderDirectionALL lineWidth:1 color:HEXCOLOR(0x959595)];
        [self.goodsEditBkgView addSubview:_countTextField];
        [_countTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.addLabel.mas_left).with.offset(1);
            make.top.equalTo(self.addLabel);
            make.bottom.equalTo(self.addLabel);
            
            if (ScreenWidth >320) {
                make.width.mas_equalTo(@40);
            } else {
                make.width.mas_equalTo(40 *WIDTH);
            }
        }];
    }
    return _countTextField;
}
- (UILabel *)subtractLabel {
    if (!_subtractLabel) {
        _subtractLabel = [UILabel new];
        _subtractLabel.font = APPFONT(16);
        _subtractLabel.cornerRadius = 1;
        _subtractLabel.text = @"-";
        _subtractLabel.textColor = HEXCOLOR(0xdbdbdb);
        _subtractLabel.textAlignment = NSTextAlignmentCenter;
        [_subtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
        [self.goodsEditBkgView addSubview:_subtractLabel];
        [_subtractLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.countTextField.mas_left).with.offset(1);
            make.top.equalTo(self.countTextField);
            make.bottom.equalTo(self.countTextField);
            make.width.equalTo(self.addLabel);
        }];
        
        [_subtractLabel tapUpWithBlock:^(UIView * v) {
            /**
            if (self.countTextField.text.integerValue <= self.model.minimum) {
                NSString * str = [NSString stringWithFormat:kGoodsBuyMinCountMessage@"%@", @(self
                                  .model.minimum)];
                jxt_showAlertTitle(str);
                return;
            }
            NSInteger num = self.countTextField.text.integerValue - 1;
            
            self.model.tempNumber = num;
            self.countTextField.text = [NSString stringWithFormat:@"%@", @(num)];
            self.model.changeEdit = YES;
             */
            [self updateUIData];
        }];
    }
    return _subtractLabel;
}
- (UILabel *)goodsPriceLabel {
    if (!_goodsPriceLabel) {
        _goodsPriceLabel = [UILabel new];
        _goodsPriceLabel.font = APPFONT(14);
        _goodsPriceLabel.textColor = Color175030;
        [self.goodsEditBkgView addSubview:_goodsPriceLabel];
        [_goodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsEditBkgView).with.offset(8);
            make.bottom.equalTo(self.goodsEditBkgView).with.offset(-10);
            make.right.equalTo(self.subtractLabel.mas_left).with.offset(-10);
        }];
    }
    return _goodsPriceLabel;
}
- (UIView *)defectMarkView {
    if (!_defectMarkView) {
        _defectMarkView = [UIView new];
        _defectMarkView.hidden = YES;
        _defectMarkView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_defectMarkView];
        [_defectMarkView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.selectLabel).with.offset(-6);
            make.right.equalTo(self.selectLabel).with.offset(2);
            make.centerY.equalTo(self.selectLabel);
            make.height.mas_equalTo(22);
        }];
        
        UILabel * defectMarkLabel = [UILabel new];
        defectMarkLabel.cornerRadius = 2;
        defectMarkLabel.text = @"失效";
        defectMarkLabel.font = APPFONT(10);
        defectMarkLabel.textColor = [UIColor whiteColor];
        defectMarkLabel.backgroundColor = HEXCOLORALPHA(000000, 0.7);
        defectMarkLabel.textAlignment = NSTextAlignmentCenter;
        [_defectMarkView addSubview:defectMarkLabel];
        [defectMarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.defectMarkView);
        }];
    }
    return _defectMarkView;
}
- (UILabel *)lotteryLabel {
    if (!_lotteryLabel) {
        _lotteryLabel = [[UILabel alloc] init];
        _lotteryLabel.font = APPFONT(14);
        _lotteryLabel.textColor = Color175030;
        _lotteryLabel.layer.masksToBounds = YES;
        _lotteryLabel.layer.cornerRadius = 2;
        _lotteryLabel.layer.borderColor = [Color175030 CGColor];
        _lotteryLabel.layer.borderWidth = 1;
        [self.goodsDataBkgView addSubview:_lotteryLabel];
        [_lotteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.goodsTitleLabel);
        }];
    }
    return _lotteryLabel;
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = Color217;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.and.right.equalTo(self.contentView);
            make.left.equalTo(self.contentView).with.offset(15);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _lineView;
}
- (UIView *)cellSepView {
    if (!_cellSepView) {
        _cellSepView = [[UIView alloc] init];
        _cellSepView.backgroundColor = Color217;
        _cellSepView.hidden = NO;
        [self.contentView addSubview:_cellSepView];
        [_cellSepView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.right.equalTo(self.contentView);
            make.left.equalTo(self.contentView).with.offset(15);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _cellSepView;
}
- (ShoppingCartStoreTagView *)shoppingCartStoreTagView {
    if (!_shoppingCartStoreTagView) {
        _shoppingCartStoreTagView = [ShoppingCartStoreTagView new];
        _shoppingCartStoreTagView.hidden = NO;
        _shoppingCartStoreTagView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_shoppingCartStoreTagView];
        [_shoppingCartStoreTagView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.and.top.equalTo(self.contentView);
            make.height.mas_equalTo(25);
        }];
    }
    return _shoppingCartStoreTagView;
}
- (UILabel *)topAddLabel {
    if (!_topAddLabel) {
        _topAddLabel = [UILabel new];
        _topAddLabel.font = APPFONT(16);
        _topAddLabel.text = @"+";
        _topAddLabel.cornerRadius = 1;
        _topAddLabel.textColor = HEXCOLOR(0x000000);
        _topAddLabel.textAlignment = NSTextAlignmentCenter;
        [self.goodsDataBkgView addSubview:_topAddLabel];
        [_topAddLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.goodsDataBkgView).with.offset(-15);
            make.bottom.equalTo(self.goodsDataBkgView).with.offset(-10);
            if (ScreenWidth >320) {
                make.height.mas_equalTo(@25);
                make.width.mas_equalTo(@30);
            } else {
                make.height.mas_equalTo(25 *WIDTH);
                make.width.mas_equalTo(30 *WIDTH);
            }
            
        }];
        
        [_topAddLabel tapUpWithBlock:^(UIView * v) {
            NSInteger num = self.topCountTextField.text.integerValue + 1;
            /**
            if (num > self.model.inventory) {
                num -= 1;
            }
            if (self.model.limitBuyState == NewStoreLimitBuyState_Process) {
                //不敢动前面的，限时购另外加个判断~
                if (num > self.kMaxNum) {
                    num -= 1;
                }
            }
            
            self.model.tempNumber = num;
            self.topCountTextField.text = [NSString stringWithFormat:@"%@", @(num)];
            [self topUpdateUIData];
            */
            
            if (self.cliekedNumChangeBlock) {
                self.cliekedNumChangeBlock();
            }
        }];
    }
    return _topAddLabel;
}
- (NumberKeyboardAndToolTextField *)topCountTextField {
    if (!_topCountTextField) {
        _topCountTextField = [[NumberKeyboardAndToolTextField alloc] init];
        _topCountTextField.font = APPFONT(14);
        _topCountTextField.text = @"1";
        _topCountTextField.textAlignment = NSTextAlignmentCenter;
        _topCountTextField.keyboardType = UIKeyboardTypeNumberPad;
        _topCountTextField.delegate = self;
        _topCountTextField.tag = 2;
        [_topCountTextField addTarget:self action:@selector(topChangeTextField:) forControlEvents:UIControlEventEditingChanged];
        [_topCountTextField limitTextLength:4];
        [_topCountTextField roundBorderWithBorderDirection:BorderDirectionALL lineWidth:1 color:HEXCOLOR(0x959595)];
        [self.goodsDataBkgView addSubview:_topCountTextField];
        [_topCountTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.topAddLabel.mas_left).with.offset(1);
            make.top.equalTo(self.topAddLabel);
            make.bottom.equalTo(self.topAddLabel);
            
            if (ScreenWidth >320) {
                make.width.mas_equalTo(@40);
            } else {
                make.width.mas_equalTo(40 *WIDTH);
            }
            
        }];
    }
    return _topCountTextField;
}
- (UILabel *)topSubtractLabel {
    if (!_topSubtractLabel) {
        _topSubtractLabel = [UILabel new];
        _topSubtractLabel.font = APPFONT(16);
        _topSubtractLabel.cornerRadius = 1;
        _topSubtractLabel.text = @"-";
        _topSubtractLabel.textColor = HEXCOLOR(0xdbdbdb);
        _topSubtractLabel.textAlignment = NSTextAlignmentCenter;
        [_topSubtractLabel roundBorderWithBorderDirection:BorderDirectionLeft | BorderDirectionTop | BorderDirecionBottom lineWidth:1 color:HEXCOLOR(0xdbdbdb)];
        [self.goodsDataBkgView addSubview:_topSubtractLabel];
        [_topSubtractLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.topCountTextField.mas_left).with.offset(1);
            make.top.equalTo(self.topCountTextField);
            make.bottom.equalTo(self.topCountTextField);
            make.width.equalTo(self.topAddLabel);
        }];
        
        [_topSubtractLabel tapUpWithBlock:^(UIView * v) {
            if (self.topCountTextField.text.integerValue <= self.model.minimum) {
                /**
                NSString * str = [NSString stringWithFormat:kGoodsBuyMinCountMessage@"%@", @(self
                                  .model.minimum)];
                jxt_showAlertTitle(str);
                 */
                return;
            }
            NSInteger num = self.topCountTextField.text.integerValue - 1;
            /**
            self.model.tempNumber = num;
            self.topCountTextField.text = [NSString stringWithFormat:@"%@", @(num)];
            [self topUpdateUIData];
            */
            if (self.cliekedNumChangeBlock) {
                self.cliekedNumChangeBlock();
            }
        }];
    }
    return _topSubtractLabel;
}
/** 商品标题推荐文字 */
- (UILabel *)dpLabel {
    if (!_dpLabel) {
        _dpLabel = [[UILabel alloc] init];
        _dpLabel.font = APPFONT(11);
        _dpLabel.textColor = [UIColor whiteColor];;
        _dpLabel.textAlignment = NSTextAlignmentCenter;
        _dpLabel.backgroundColor = Color175030;
        _dpLabel.cornerRadius = 1;
        [self.goodsDataBkgView addSubview:_dpLabel];
        
        [self.dpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsTitleLabel);
            make.top.equalTo(self.goodsTitleLabel).with.offset(2);
            make.height.mas_equalTo(14);
        }];
    }
    return _dpLabel;
}
/** 商品标题标签文字 */
- (UILabel *)markLabel {
    if (!_markLabel) {
        NSString *markName = @"跨境";
        _markLabel = [[UILabel alloc] init];
        _markLabel.text = markName;
        _markLabel.font = APPFONT(12);
        _markLabel.textAlignment = NSTextAlignmentCenter;
        _markLabel.backgroundColor = [UIColor clearColor];
        _markLabel.layer.borderWidth = 0.5;
        _markLabel.layer.cornerRadius = 1;
        _markLabel.layer.masksToBounds = YES;
        _markLabel.textColor = Color175030;
        _markLabel.layer.borderColor = Color175030.CGColor;
        [self.contentView addSubview:_markLabel];
        CGFloat titleH = [markName boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : APPFONT(12)} context:nil].size.height;
        [_markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.goodsTitleLabel).offset(1);
            make.left.equalTo(self.goodsTitleLabel);
            make.width.mas_equalTo(33);
            make.height.mas_equalTo(titleH);
        }];
    }
    return _markLabel;
}
/**
- (ConfirmIdentityView *)identityView {
    if (!_identityView) {
        _identityView = [[ConfirmIdentityView alloc] init];
        [self.contentView addSubview:_identityView];
        [_identityView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(40);
        }];
    }
    return _identityView;
}
- (void)instructionBtnAction {
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:
                                          [[UserIdentityInstructionView alloc] initWithFrame:CGRectMake(0, 0, 300, 247)]
                                                                          preferredStyle:TYAlertControllerStyleAlert];
    alertController.backgoundTapDismissEnable = YES;
    [APP.rootViewController.navigationController presentViewController:alertController
                                               animated:YES
                                             completion:nil];
}
*/
- (AffirmOrdeGoodsNumberView *)goodsNumerView {
    if (!_goodsNumerView) {
        
        UIView *goodsNumerContentView = [[UIView alloc] init];
        [self.contentView addSubview:goodsNumerContentView];
        [goodsNumerContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(40);
        }];
        self.goodsNumerContentView = goodsNumerContentView;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"购买数量:";
        titleLabel.font = APPFONT(15);
        titleLabel.textColor = Color34;
        [goodsNumerContentView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(goodsNumerContentView).offset(15);
            make.bottom.height.equalTo(goodsNumerContentView);
        }];
        
        UIView *topView = [[UIView alloc] init];
        topView.backgroundColor = Color217;
        [goodsNumerContentView addSubview:topView];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(goodsNumerContentView).offset(15);
            make.right.equalTo(goodsNumerContentView).offset(-15);
            make.top.equalTo(titleLabel);
            make.height.mas_equalTo(0.5);
        }];
        
        _goodsNumerView = [[AffirmOrdeGoodsNumberView alloc] init];
        [goodsNumerContentView addSubview:_goodsNumerView];
        [_goodsNumerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(goodsNumerContentView).offset(-15);
            make.bottom.equalTo(goodsNumerContentView).offset(-5);
            make.width.mas_equalTo(130);
            make.height.mas_equalTo(30);
        }];
        
        [goodsNumerContentView addSubview:self.editLimitMaxLabel];
        [self.editLimitMaxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titleLabel);
            make.right.equalTo(self.goodsNumerView.mas_left).offset(-10);
            make.height.mas_equalTo(21);
        }];
    }
    return _goodsNumerView;
}


#pragma mark - 限时购新增
- (UILabel *)limitBuyInfoLabel
{
    if (!_limitBuyInfoLabel) {
        _limitBuyInfoLabel = [[UILabel alloc]init];
        _limitBuyInfoLabel.font = APPFONT(11);
        _limitBuyInfoLabel.textColor = Color175030;
        _limitBuyInfoLabel.numberOfLines = 1;
        [self.goodsDataBkgView addSubview:_limitBuyInfoLabel];
        [_limitBuyInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsTitleLabel);
            make.right.equalTo(self.goodsDataBkgView).offset(-10);
            make.top.equalTo(self.subheadLabel.mas_bottom).offset(4);
            make.bottom.lessThanOrEqualTo(self.sellPriceLabel.mas_top).offset(-5);
        }];
    }
    return _limitBuyInfoLabel;
}
- (UILabel *)carLimitMaxLabel
{
    if (!_carLimitMaxLabel) {
        _carLimitMaxLabel = [[UILabel alloc]init];
        _carLimitMaxLabel.font = APPFONT(12);
        _carLimitMaxLabel.textColor = Color20812847;
        _carLimitMaxLabel.numberOfLines = 1;
        [self.goodsDataBkgView addSubview:_carLimitMaxLabel];
        [_carLimitMaxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.sellPriceLabel.mas_right).with.offset(5);
            make.centerY.equalTo(self.sellPriceLabel);
            make.height.mas_equalTo(14);
        }];
    }
    return _carLimitMaxLabel;
}
- (UILabel *)editLimitMaxLabel
{
    if (!_editLimitMaxLabel) {
        _editLimitMaxLabel = [[UILabel alloc]init];
        _editLimitMaxLabel.font = APPFONT(15);
        _editLimitMaxLabel.textColor = Color20812847;
        _editLimitMaxLabel.numberOfLines = 1;
    }
    return _editLimitMaxLabel;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
